/**
 * yeahmobi.com Inc.
 * Copyright © 2014 YeahMobi | All Rights Reserved.
 */   
    
package com.ndp.fb.rdb.db.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.ndp.fb.rdb.api.UserAudienceTemplateLogRdbService;
import com.ndp.fb.rdb.db.DaoTemplate;
import com.ndp.fb.rdb.db.impl.mapper.DefaultRowMapper;
import com.ndp.fb.rdb.model.AdCampaignGroup;
import com.ndp.fb.rdb.model.UserAudienceTemplate;
import com.ndp.fb.rdb.model.UserAudienceTemplateLog;

import java.util.List;

/**
 * @Title: UserAudienceTemplateLogRdbServiceImpl.java
 * @Copyright: Copyright © 2015
 * @Description: 
 * @Company: yeahmobi
 * @Created on 上午10:33:42
 * @author giser.yang
 */
@Service
public class UserAudienceTemplateLogRdbServiceImpl extends DaoTemplate implements
		UserAudienceTemplateLogRdbService {

	/**  描述   (@author: giser.yang) */      
	    
	private static final long serialVersionUID = -1968085492996288540L;

	/** 
	 * @discription
	 * @author giser.yang       
	 * 创建时间 2015年7月9日 上午10:33:43      
	 * @param userAudienceTemplateLog
	 * @return     
	 * @see com.ndp.fb.rdb.api.UserAudienceTemplateLogRdbService#saveUserAudienceTemplateLog(com.ndp.fb.rdb.model.UserAudienceTemplateLog)     
	 */

	@Override
	public Long saveUserAudienceTemplateLog(UserAudienceTemplateLog userAudienceTemplateLog) {
		return saveResultId(userAudienceTemplateLog);
	}

	/** 
	 * @discription
	 * @author giser.yang       
	 * 创建时间 2015年7月9日 上午10:33:43      
	 * @param userId
	 * @param productConfigurationId
	 * @param fbConnectionObjectId
	 * @param pageNow
	 * @param pageSize
	 * @return     
	 * @see com.ndp.fb.rdb.api.UserAudienceTemplateLogRdbService#findLastSaveAudienceTemplate(java.lang.String, java.lang.Long, java.lang.Long, int, int)     
	 */

	@Override
	public List<Long> findLastSaveAudienceTemplate(String userId,
			Long productConfigurationId, Long fbConnectionObjectId,
			int pageNow, int pageSize) {
		String sql = "SELECT DISTINCT uatl.user_audience_template_id FROM ( SELECT  * FROM `user_audience_template_log` WHERE user_id = ? and fb_connection_object_id = ? and "
				+ "product_configuration_id = ? ORDER BY updated_time DESC) as uatl limit ?,?";
		return getJdbcTemplate().queryForList(sql,new Object[]{userId,fbConnectionObjectId, productConfigurationId,pageNow-1,pageSize},Long.class);
	}

	@Override
	public UserAudienceTemplate findById(Long id) {
		String sql = "select * from user_audience_template where id=?";
		return findOne(sql, new Object[]{id}, DefaultRowMapper.autoRowMapper(UserAudienceTemplate.class));
	}
}
